//
//  ShareView.m
//  newBooks
//
//  Created by 张 on 2018/11/22.
//  Copyright © 2018年 pro2. All rights reserved.
//

#import "ShareView.h"

@implementation ShareView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
static UINib *ShareViewNib = nil;
+ (instancetype)ShareViewNib{
    if (ShareViewNib == nil) {
        ShareViewNib = [UINib nibWithNibName:@"ShareView" bundle:nil];
    }
    ShareView *alert = [[ShareViewNib instantiateWithOwner:nil options:nil] lastObject];
    UIView * btnView = [alert.baseView viewWithTag:999];
    for (QMUIButton * btn in btnView.subviews) {
        btn.imagePosition = QMUIButtonImagePositionTop;
    }
    return alert;
}

+ (instancetype)initWithShareChooseViewChooseBlock:(void(^)(NSInteger selIndex))chooseBlock 
{
    ShareView * chooseView = [ShareView ShareViewNib];
    [chooseView setFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    chooseView.baseViewHeight.constant = 123 + SafeAreaInsetsConstantForDeviceWithNotch.bottom;
    chooseView.ShareChooseBlock = chooseBlock;
    
    [[UIApplication sharedApplication].keyWindow addSubview:chooseView];
    [MenuAnimation ShowAnimation:chooseView completion:^(BOOL finished) {
        chooseView.backgroundColor = RGBAlpha(0, 0, 0, 0.5);
    }];
    
    return chooseView;
}

#pragma mark - action

- (IBAction)shareTypeClick:(UIButton *)sender {
    self.ShareChooseBlock(sender.tag);
    NSLog(@"%d",sender.tag);
    self.backgroundColor = RGBAlpha(0, 0, 0, 0);
    [MenuAnimation HiddenAnimation:self completion:^(BOOL finished) {
        [self.baseView removeFromSuperview];
        [self removeFromSuperview];
    }];
}

- (IBAction)cancleBlock:(id)sender {
    if (self.cancleBlock) {
        self.cancleBlock();
    }
    self.backgroundColor = RGBAlpha(0, 0, 0, 0);
    [MenuAnimation HiddenAnimation:self completion:^(BOOL finished) {
        [self.baseView removeFromSuperview];
        [self removeFromSuperview];
    }];
    
}


@end
